#include "mna.h"

void mna_create_dense(double **mna, double **b_vector, int N, int m2)
{
	char type;
	int p,m;
	int m2_index;
	double value;
	int i;
	int n = N + m2 - 1;

	double *MNA;
	MNA = *mna = (double *)malloc(n*n*sizeof(double));
	if(MNA == NULL){
		printf("Fatal error: Not enough memory!\n aborting...\n");
		exit(42);
	}
	memset(MNA, 0, n*n*sizeof(double));

	if(*b_vector == NULL){	//in case of C mode dont create a new b	
		double *b;
		b = *b_vector = (double *)malloc(n*sizeof(double));
		if(b == NULL){
			printf("Fatal error: Not enough memory!\n aborting...\n");
			exit(42);
		}
		memset(b, 0, n*sizeof(double));
	}
}

void mna_create_sparse(cs **mna, double **b_vector, int N, int m2)
{
	char type;
	int p,m;
	int m2_index;
	double value;
	int n = N + m2 - 1;	

	long *Mi, *Mj;
	double *Mx;
	int cnt = 0;

	cs *MNA;
	MNA = cs_spalloc(n, n, 4*n*n, 1, 1);
	MNA->nz = 4*n*n;

	*mna = MNA;
	
	if(*b_vector == NULL){
		double *b;
		b = *b_vector = (double *)malloc(n*sizeof(double));
		memset(b, 0, n*sizeof(double));
	}
}
